package com.yonyou.base.flower.dao;

import com.yonyou.base.flower.model.Flower;
import com.yonyou.hrcloud.adder.ext.MBDao;
import com.yonyou.hrcloud.adder.model.param.Limit;
import org.apache.ibatis.annotations.*;

import java.util.List;

@MBDao
public interface IFlowerStorageDao {

    @Delete("delete from app_flower where id = #{id}")
    void deleteFlower(@Param("id") String flowerId);

    @Select("<script>select * from app_flower<if test=\"userId!=null\"> where creator = #{userId}</if> order by creationtime desc</script>")
    List<Flower> queryFlower(@Param("userId") String userId, Limit limit);

    @Select("<script>select count(id) from app_flower<if test=\"userId!=null\"> where creator = #{userId}</if></script>")
    Long queryFlowerCount(@Param("userId") String userId);

    @Insert("insert into app_flower (id,flower_name,flower_link,flower_desc,flower_pic,creationtime,creator,version,dr) " +
            "values (#{id},#{flower_name},#{flower_link},#{flower_desc},#{flower_pic},#{creationtime},#{creator},0,0)")
    void insertFlower(Flower flower);

    @Update("update app_flower set flower_name=#{flower_name},flower_link=#{flower_link},flower_desc=#{flower_desc},flower_pic#{flower_pic}," +
            "modifiedtime=#{modifiedtime},modifier=#{modifier} where id=#{id}")
    void updateFlower(Flower flower);

    @Select("select count(id) from app_flower")
    Integer queryAllFlowerCount();
}
